﻿using SGSBillBoard.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SGSBillBoard.Context
{
	public class SGSInitializer : DropCreateDatabaseIfModelChanges<SGSContext>
	{
		protected override void Seed(SGSContext context)
		{
			var f1 = new string[] { "曹操", "司马懿", "夏侯惇", "张辽", "许褚", "郭嘉", "甄姬", "曹仁", "夏侯渊", "典韦", "荀彧", "徐晃", "曹丕", "张郃", "邓艾", "曹洪", "李典", "臧霸", "乐进" };
			var f2 = new string[] { "刘备", "关羽", "张飞", "诸葛亮", "赵云", "马超", "黄月英", "黄忠", "魏延", "卧龙诸葛亮", "庞统", "孟获", "祝融", "刘禅", "姜维", "蒋琬费祎", "马岱", "糜夫人", "甘夫人" };
			var f3 = new string[] { "孙权", "甘宁", "吕蒙", "黄盖", "周瑜", "大乔", "孙尚香", "陆逊", "周泰", "小乔", "太史慈", "孙坚", "鲁肃", "张昭纮", "蒋钦", "徐盛", "孙策", "陈武董袭", "丁奉" };
			var f4 = new string[] { "华佗", "吕布", "貂蝉", "张角", "庞德", "颜良文丑", "袁绍", "贾诩", "蔡文姬", "马腾", "孔融", "纪灵", "田丰", "潘凤", "于吉", "何太后", "董卓", "张任" };
			var fighters = new List<Fighter>();
			fighters.AddRange(f1.Select(x => new Fighter() { Name = x, Nation = Nations.魏 }));
			fighters.AddRange(f2.Select(x => new Fighter() { Name = x, Nation = Nations.蜀 }));
			fighters.AddRange(f3.Select(x => new Fighter() { Name = x, Nation = Nations.吴 }));
			fighters.AddRange(f4.Select(x => new Fighter() { Name = x, Nation = Nations.群 }));

			context.Fighters.AddRange(fighters);
			context.SaveChanges();

			var p1 = new string[] { "Alex", "David", "Jimmy", "Julia" };
			var p2 = new string[] { "Elvin" };
			var p3 = new string[] { "Kent" };
			var p4 = new string[] { "Shine" };
			var players = new List<Player>();
			players.AddRange(p1.Select(x => new Player() { Name = x, Department = "RTP" }));
			players.AddRange(p2.Select(x => new Player() { Name = x, Department = "AA" }));
			players.AddRange(p3.Select(x => new Player() { Name = x, Department = "Timing" }));
			players.AddRange(p4.Select(x => new Player() { Name = x, Department = "Support" }));
			context.Players.AddRange(players);
			context.SaveChanges();


			var session = new Session { GameDate = DateTime.Now.Date, PlayerNumber = 4 };

			var fighter = context.Fighters.SingleOrDefault(x => x.Name == "马岱");
			var fighter1 = context.Fighters.SingleOrDefault(x => x.Name == "黄忠");
			var player1 = context.Players.SingleOrDefault(x => x.Name == "Elvin");
			var score = new Score { Player = player1, IsWinner = true, IsShowFirst = true, Session = session, Chief = fighter, Vice = fighter1 };



			var fighter2 = context.Fighters.SingleOrDefault(x => x.Name == "李典");
			var fighter3 = context.Fighters.SingleOrDefault(x => x.Name == "徐晃");
			var player2 = context.Players.SingleOrDefault(x => x.Name == "Alex");
			var score1 = new Score { Player = player2, IsWinner = false, IsShowFirst = false, Session = session, Chief = fighter2, Vice = fighter3 };

			var fighter4 = context.Fighters.SingleOrDefault(x => x.Name == "诸葛亮");
			var fighter5 = context.Fighters.SingleOrDefault(x => x.Name == "孟获");
			var player3 = context.Players.SingleOrDefault(x => x.Name == "Kent");
			var score2 = new Score { Player = player3, IsWinner = true, IsShowFirst = false, Session = session, Chief = fighter4, Vice = fighter5 };

			var fighter6 = context.Fighters.SingleOrDefault(x => x.Name == "貂蝉");
			var fighter7 = context.Fighters.SingleOrDefault(x => x.Name == "于吉");
			var player4 = context.Players.SingleOrDefault(x => x.Name == "Shine");
			var score3 = new Score { Player = player4, IsWinner = false, IsShowFirst = false, Session = session, Chief = fighter5, Vice = fighter6 };

			context.Scores.Add(score);
			context.Scores.Add(score1);
			context.Scores.Add(score2);
			context.Scores.Add(score3);
			context.SaveChanges();

			//var player = new Player
			//{
			//    Name = "Alex",
			//    Department = "RTP",
			//    Chief = new Fighter { Name = "HZ", Nation = Nations.蜀 },
			//    Vice = new Fighter { Name = "ZY", Nation = Nations.蜀 },
			//    IsWinner = false
			//};
			////context.Players.Add(player);

			//var session = new Session { GameDate = DateTime.Now, TotalPlayers = new List<Player> { player } };
			//context.Sessions.Add(session);
			//context.SaveChanges();
			//base.Seed(context);
		}
	}
}
